import {defineStore} from 'pinia'
import {ref,computed} from 'vue'
import {getCategoriesAPI} from "@/apis/home.js";

export const useCategoryStore = defineStore('category', () => {
        const categories = ref()

        const getCategories = async () => {
            const res = await getCategoriesAPI()
            categories.value = res.data
        }
        const alertCategories =(data)=>{
            categories.value=data
        }
        const clearCategories=()=>{
            categories.value=null
        }

        const isEmpty=computed(()=>{
            return !categories.value
        })


        return {categories, getCategories,alertCategories,clearCategories,isEmpty}
    },
    {
        //持久化存储
        persist: true,
    }
)
